//
//  NSAttributedString+Extension.m
//  XYTextView
//
//  Created by 学大教育 on 2020/7/17.
//  Copyright © 2020 jutuo. All rights reserved.
//

#import "NSAttributedString+Extension.h"
@implementation NSAttributedString (Extension)
- (NSData *)archiveToData
{
    NSData *data = nil;
    @try {
        if (@available(iOS 12.0, *)) {
            data = [NSKeyedArchiver archivedDataWithRootObject:self requiringSecureCoding:NO error:nil];
        }else{
            data = [NSKeyedArchiver archivedDataWithRootObject:self];
        }
        
    } @catch (NSException *exception) {
        NSLog(@"%@",exception);
    }
    return data;
}
+ (instancetype)unarchiveFromData:(NSData *)data
{
    NSAttributedString *one = nil;
    @try {
        one = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    } @catch (NSException *exception) {
        NSLog(@"%@",exception);
    }
    return one;
}
- (NSDictionary<NSString *,id> *)attributes
{
    return [self attributesAtIndex:0];
}

- (NSDictionary<NSAttributedStringKey, id> *)attributesAtIndex:(NSUInteger)index
{
    if (index >= self.length || self.length == 0) {
        return nil;
    }
    return [self attributesAtIndex:index effectiveRange:NULL];
}

- (nullable id)attribute:(NSAttributedStringKey)attrName atIndex:(NSUInteger)index
{
    if (!attrName) return nil;
    if (index > self.length || self.length == 0) return nil;
    if (self.length > 0 && index == self.length) index--;
    return [self attribute:attrName atIndex:index effectiveRange:NULL];
}

- (UIFont *)font
{
    return [self fontAtIndex:0];
}

- (nullable UIFont *)fontAtIndex:(NSUInteger)index
{
    UIFont *font = [self attribute:NSFontAttributeName atIndex:index];
    return font;
}

- (NSNumber *)kern
{
    return [self kernAtIndex:0];
}

- (NSNumber *)kernAtIndex:(NSUInteger)index
{
    NSNumber *kern = [self attribute:NSKernAttributeName atIndex:index];
    return kern;
}

- (UIColor *)color
{
    return [self colorAtIndex:0];
}

- (UIColor *)colorAtIndex:(NSUInteger)index
{
    UIColor *color = [self attribute:NSForegroundColorAttributeName atIndex:index];
    if (!color) {
        CGColorRef ref = (__bridge CGColorRef)([self attribute:(NSString *)kCTForegroundColorAttributeName atIndex:index]);
        color = [UIColor colorWithCGColor:ref];
    }
    if (color && ![color isKindOfClass:[UIColor class]]) {
        if (CFGetTypeID((__bridge CFTypeRef)(color)) == CGColorGetTypeID()) {
            color = [UIColor colorWithCGColor:(__bridge CGColorRef)(color)];
        }else{
            color = nil;
        }
    }
    return color;
}

- (UIColor *)backgroundColor
{
    return [self backgroundColorAtIndex:0];
}

- (UIColor *)backgroundColorAtIndex:(NSUInteger)index
{
    return [self attribute:NSBackgroundColorAttributeName atIndex:index];
}

- (NSNumber *)strokeWidth
{
    return [self strokeWidthAtIndex:0];
}

- (NSNumber *)strokeWidthAtIndex:(NSUInteger)index
{
    return [self attribute:NSStrokeWidthAttributeName atIndex:index];
}

- (UIColor *)strokeColor
{
    return [self strokeColorAtIndex:0];
}

- (UIColor *)strokeColorAtIndex:(NSUInteger)index
{
    UIColor *color = [self attribute:NSStrokeColorAttributeName atIndex:index];
    if (!color) {
          CGColorRef ref = (__bridge CGColorRef)([self attribute:(NSString *)kCTStrokeColorAttributeName atIndex:index]);
          color = [UIColor colorWithCGColor:ref];
      }
      return color;
}

- (NSShadow *)shadow
{
    return [self shadowAtIndex:0];
}

- (NSShadow *)shadowAtIndex:(NSUInteger)index
{
    NSShadow *shadow = [self attribute:NSShadowAttributeName atIndex:index];
    return shadow;
}

- (NSUnderlineStyle)strikethroughStyle
{
    return [self strikethroughStyleAtIndex:0];
}

- (NSUnderlineStyle)strikethroughStyleAtIndex:(NSUInteger)index
{
    NSNumber *style = [self attribute:NSStrikethroughStyleAttributeName atIndex:index];
    return style.integerValue;
}

- (UIColor *)strikethroughColor
{
    return [self strikethroughColorAtIndex:0];
}

- (UIColor *)strikethroughColorAtIndex:(NSUInteger)index
{
    return [self attribute:NSStrikethroughColorAttributeName atIndex:index];
}

- (NSUnderlineStyle)underlineStyle
{
    return [self underlineStyleAtIndex:0];
}
- (NSUnderlineStyle)underlineStyleAtIndex:(NSUInteger)index
{
    NSNumber *style = [self attribute:NSUnderlineStyleAttributeName atIndex:index];
    return style.integerValue;
}

- (UIColor *)underlineColor
{
    return [self underlineColorAtIndex:0];
}

- (UIColor *)underlineColorAtIndex:(NSUInteger)index
{
    return [self attribute:NSUnderlineColorAttributeName atIndex:index];
}

- (NSNumber *)ligature
{
    return [self ligatureAtIndex:0];
}

- (NSNumber *)ligatureAtIndex:(NSUInteger)index
{
    return [self attribute:NSLigatureAttributeName atIndex:index];
}

- (NSString *)textEffect
{
    return [self textEffectAtIndex:0];
}

- (NSString *)textEffectAtIndex:(NSUInteger)index
{
    return [self attribute:NSTextEffectAttributeName atIndex:index];
}

- (NSNumber *)obliqueness
{
    return [self obliquenessAtIndex:0];
}

- (NSNumber *)obliquenessAtIndex:(NSUInteger)index
{
    return [self attribute:NSObliquenessAttributeName atIndex:0];
}

- (NSNumber *)expansion
{
    return [self expansionAtIndex:0];
}

- (NSNumber *)expansionAtIndex:(NSUInteger)index
{
    return [self attribute:NSExpansionAttributeName atIndex:0];
}

- (NSNumber *)baselineOffset
{
    return [self baselineOffsetAtIndex:0];
}

- (nullable NSNumber *)baselineOffsetAtIndex:(NSUInteger)index
{
    return [self attribute:NSBaselineOffsetAttributeName atIndex:index];
}
- (BOOL)verticalGlyphForm
{
    return [self verticalGlyphFormAtIndex:0];
}
- (BOOL)verticalGlyphFormAtIndex:(NSUInteger)index
{
    return [self attribute:NSVerticalGlyphFormAttributeName atIndex:index];
}

- (NSString *)language
{
    return [self languageAtIndex:0];
}

- (NSString *)languageAtIndex:(NSUInteger)index
{
    return [self attribute:(__bridge id)kCTLanguageAttributeName atIndex:index];
}

- (NSArray<NSNumber *> *)writingDirection
{
    return [self writingDirectionAtIndex:0];
}

- (NSArray<NSNumber *> *)writingDirectionAtIndex:(NSUInteger)index
{
    return [self attribute:(__bridge id)kCTWritingDirectionAttributeName atIndex:index];
}

- (NSParagraphStyle *)paragraphStyle
{
    return [self paragraphStyleAtIndex:0];
}

- (NSParagraphStyle *)paragraphStyleAtIndex:(NSUInteger)index
{
    NSParagraphStyle *style = [self attribute:NSParagraphStyleAttributeName atIndex:index];
   
    return style;
}
#define XYParagraphAttribute(_attr_)\
NSParagraphStyle *style = self.paragraphStyle; \
if (!style) style = [NSParagraphStyle defaultParagraphStyle]; \
return style. _attr_;

#define XYParagraphAttributeAtIndex(_attr_) \
NSParagraphStyle *style = [self paragraphStyleAtIndex:index]; \
if (!style) style = [NSParagraphStyle defaultParagraphStyle]; \
return style. _attr_;

- (NSTextAlignment)alignment
{
    XYParagraphAttribute(alignment);
}
- (NSTextAlignment)alignmentAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(alignment);
}
- (NSLineBreakMode)lineBreakMode
{
    XYParagraphAttribute(lineBreakMode);
}
- (NSLineBreakMode)lineBreakModeAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(lineBreakMode);
}
- (CGFloat)lineSpacing
{
    XYParagraphAttribute(lineSpacing);
}
- (CGFloat)lineSpacingAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(lineSpacing);
}

- (CGFloat)paragraphSpacingBefore
{
    XYParagraphAttribute(paragraphSpacingBefore);
}

- (CGFloat)paragraphSpacingBeforeAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(paragraphSpacingBefore);
}

- (CGFloat)firstLineHeadIndent
{
    XYParagraphAttribute(firstLineHeadIndent);
}

- (CGFloat)firstLineHeadIndentAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(firstLineHeadIndent);
}

- (CGFloat)headIndent
{
    XYParagraphAttribute(headIndent);
}

- (CGFloat)headIndentAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(headIndent);
}

- (CGFloat)tailIndent
{
    XYParagraphAttribute(tailIndent);
}

- (CGFloat)tailIndentAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(tailIndent);
}

- (CGFloat)minimumLineHeight
{
    XYParagraphAttribute(minimumLineHeight);
}

- (CGFloat)minimumLineHeightAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(minimumLineHeight);
}

- (CGFloat)maximumLineHeight
{
    XYParagraphAttribute(maximumLineHeight);
}

- (CGFloat)maximumLineHeightAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(maximumLineHeight);
}

- (CGFloat)lineHeightMultiple
{
    XYParagraphAttribute(lineHeightMultiple);
}
- (CGFloat)lineHeightMultipleAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(lineHeightMultiple);
}

- (NSWritingDirection)baseWritingDirection
{
    XYParagraphAttribute(baseWritingDirection);
}

- (NSWritingDirection)baseWritingDirectionAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(baseWritingDirection);
}

- (float)hyphenationFactor
{
    XYParagraphAttribute(hyphenationFactor);
}

- (float)hyphenationFactorAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(hyphenationFactor);
}

- (NSArray<NSTextTab *> *)tabStops
{
    XYParagraphAttribute(tabStops);
}

- (NSArray<NSTextTab *> *)tabStopsAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(tabStops);
}

- (CGFloat)defaultTabInterval
{
    XYParagraphAttribute(defaultTabInterval);
}

- (CGFloat)defaultTabIntervalAtIndex:(NSUInteger)index
{
    XYParagraphAttributeAtIndex(defaultTabInterval);
}


- (CGSize)sizeForContentSize:(CGSize)size
{
    CGSize result = CGSizeZero;
    
    if ([self respondsToSelector:@selector(boundingRectWithSize:options:context:)]) {
       
        CGRect rect = [self boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
        result = rect.size;
    }
    return result;
}

- (CGFloat)width {
    CGSize size = [self sizeForContentSize:CGSizeMake(HUGE, HUGE)];
    return size.width;
}
- (CGFloat)heightForContentWidth:(CGFloat)width {
    CGSize size = [self sizeForContentSize:CGSizeMake(width, HUGE)];
    return size.height;
}
@end

@implementation NSMutableAttributedString (Extension)

- (void)setAttributes:(NSDictionary<NSAttributedStringKey,id> *)attrs
{
    if (attrs == (id)[NSNull null]) attrs = nil;
    [self setAttributes:@{} range:NSMakeRange(0, self.length)];
    [attrs enumerateKeysAndObjectsUsingBlock:^(NSAttributedStringKey  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        [self setAttribute:key value:obj];
    }];
}

- (void)setAttribute:(NSString *)name value:(id)value
{
    [self setAttribute:name value:value range:NSMakeRange(0, self.length)];
}

- (void)setAttribute:(NSString *)name value:(id)value range:(NSRange)range
{
    if (!name || [NSNull isEqual:name]) return;
    if (value && ![NSNull isEqual:value]) {
        [self addAttribute:name value:value range:range];
    }else{
        [self removeAttribute:name range:range];
    }
}

- (void)removeAttributeInRange:(NSRange)range
{
    [self setAttributes:nil range:range];
}

- (void)setFont:(UIFont *)font
{
    [self setFont:font range:NSMakeRange(0, self.length)];
}

- (void)setFont:(UIFont *)font range:(NSRange)range
{
    [self setAttribute:NSFontAttributeName value:font range:range];
}

- (void)setKern:(NSNumber *)kern
{
    [self setKern:kern range:NSMakeRange(0, self.length)];
}

- (void)setKern:(NSNumber *)kern range:(NSRange)range
{
    [self setAttribute:NSKernAttributeName value:kern range:range];
}

- (void)setColor:(UIColor *)color
{
    [self setColor:color range:NSMakeRange(0, self.length)];
}

- (void)setColor:(UIColor *)color range:(NSRange)range
{
    [self setAttribute:NSForegroundColorAttributeName value:color range:range];
}

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
    [self setBackgroundColor:backgroundColor range:NSMakeRange(0, self.length)];
}

- (void)setBackgroundColor:(UIColor *)backgroundColor range:(NSRange)range
{
    [self setAttribute:NSBackgroundColorAttributeName value:backgroundColor range:range];
}

- (void)setStrokeWidth:(NSNumber *)strokeWidth
{
    [self setStrokeWidth:strokeWidth range:NSMakeRange(0, self.length)];
}

- (void)setStrokeWidth:(NSNumber *)strokeWidth range:(NSRange)range
{
    [self setAttribute:NSStrokeWidthAttributeName value:strokeWidth range:range];
}

- (void)setStrokeColor:(UIColor *)strokeColor
{
    [self setStrokeColor:strokeColor range:NSMakeRange(0, self.length)];
}

- (void)setStrokeColor:(UIColor *)strokeColor range:(NSRange)range
{
    [self setAttribute:NSStrokeColorAttributeName value:strokeColor range:range];
}

- (void)setShadow:(NSShadow *)shadow
{
    [self setShadow:shadow range:NSMakeRange(0, self.length)];
}

- (void)setShadow:(NSShadow *)shadow range:(NSRange)range
{
    [self setAttribute:NSShadowAttributeName value:shadow range:range];
}

- (void)setStrikethroughStyle:(NSUnderlineStyle)strikethroughStyle
{
    [self setStrikethroughStyle:strikethroughStyle range:NSMakeRange(0, self.length)];
}

- (void)setStrikethroughStyle:(NSUnderlineStyle)strikethroughStyle range:(NSRange)range
{
    [self setAttribute:NSStrikethroughStyleAttributeName value:@(strikethroughStyle) range:range];
}

- (void)setStrikethroughColor:(UIColor *)strikethroughColor
{
    [self setStrikethroughColor:strikethroughColor range:NSMakeRange(0, self.length)];
}

- (void)setStrikethroughColor:(UIColor *)strikethroughColor range:(NSRange)range
{
    [self setAttribute:NSStrikethroughColorAttributeName value:strikethroughColor range:range];
}

- (void)setUnderlineStyle:(NSUnderlineStyle)underlineStyle
{
    [self setUnderlineStyle:underlineStyle range:NSMakeRange(0, self.length)];
}

- (void)setUnderlineStyle:(NSUnderlineStyle)underlineStyle range:(NSRange)range
{
    [self setAttribute:NSUnderlineStyleAttributeName value:@(underlineStyle) range:range];
}

- (void)setUnderlineColor:(UIColor *)underlineColor
{
    [self setUnderlineColor:underlineColor range:NSMakeRange(0, self.length)];
}

- (void)setUnderlineColor:(UIColor *)underlineColor range:(NSRange)range
{
    [self setAttribute:NSUnderlineColorAttributeName value:underlineColor range:range];
}

- (void)setLigature:(NSNumber *)ligature
{
    [self setLigature:ligature range:NSMakeRange(0, self.length)];
}

- (void)setLigature:(NSNumber *)ligature range:(NSRange)range
{
    [self setAttribute:NSLigatureAttributeName value:ligature range:range];
}

- (void)setTextEffect:(NSString *)textEffect
{
    [self setTextEffect:textEffect range:NSMakeRange(0, self.length)];
}

- (void)setTextEffect:(NSString *)textEffect range:(NSRange)range
{
    [self setAttribute:NSTextEffectAttributeName value:textEffect range:range];
}

- (void)setObliqueness:(NSNumber *)obliqueness
{
    [self setObliqueness:obliqueness range:NSMakeRange(0, self.length)];
}
- (void)setObliqueness:(NSNumber *)obliqueness range:(NSRange)range {
   
    [self setAttribute:NSObliquenessAttributeName value:obliqueness range:range];
}
- (void)setExpansion:(NSNumber *)expansion
{
    [self setExpansion:expansion range:NSMakeRange(0, self.length)];
}

- (void)setExpansion:(NSNumber *)expansion range:(NSRange)range
{
    [self setAttribute:NSExpansionAttributeName value:expansion range:range];
}

- (void)setBaselineOffset:(NSNumber *)baselineOffset
{
    [self setBaselineOffset:baselineOffset range:NSMakeRange(0, self.length)];
}
- (void)setBaselineOffset:(NSNumber *)baselineOffset range:(NSRange)range
{
    [self setAttribute:NSBaselineOffsetAttributeName value:baselineOffset range:range];
}

- (void)setVerticalGlyphForm:(BOOL)verticalGlyphForm
{
    [self setVerticalGlyphForm:verticalGlyphForm range:NSMakeRange(0, self.length)];
}

- (void)setVerticalGlyphForm:(BOOL)verticalGlyphForm range:(NSRange)range
{
    [self setAttribute:NSVerticalGlyphFormAttributeName value:@(verticalGlyphForm) range:range];
}

- (void)setLanguage:(NSString *)language
{
    [self setLanguage:language range:NSMakeRange(0, self.length)];
}

- (void)setLanguage:(NSString *)language range:(NSRange)range
{
    [self setAttribute:(__bridge id)kCTLanguageAttributeName value:language range:range];
}

- (void)setWritingDirection:(NSArray<NSNumber *> *)writingDirection
{
    [self setWritingDirection:writingDirection range:NSMakeRange(0, self.length)];
}

- (void)setWritingDirection:(NSArray<NSNumber *> *)writingDirection range:(NSRange)range
{
    [self setAttribute:NSWritingDirectionAttributeName value:writingDirection range:range];
}

- (void)setParagraphStyle:(NSParagraphStyle *)paragraphStyle
{
    [self setParagraphStyle:paragraphStyle range:NSMakeRange(0, self.length)];
}

- (void)setParagraphStyle:(NSParagraphStyle *)paragraphStyle range:(NSRange)range
{
    [self setAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
}
#define XYParagraphStyleSet(_attr_) \
[self enumerateAttribute:NSParagraphStyleAttributeName \
                 inRange:range \
                 options:kNilOptions \
              usingBlock: ^(NSParagraphStyle *value, NSRange subRange, BOOL *stop) { \
                  NSMutableParagraphStyle *style = nil; \
                  if (value) { \
                      if (CFGetTypeID((__bridge CFTypeRef)(value)) == CTParagraphStyleGetTypeID()) { \
                          value = [NSParagraphStyle styleWithCTStyle:(__bridge CTParagraphStyleRef)(value)]; \
                      } \
                      if (value. _attr_ == _attr_) return; \
                      if ([value isKindOfClass:[NSMutableParagraphStyle class]]) { \
                          style = (id)value; \
                      } else { \
                          style = value.mutableCopy; \
                      } \
                  } else { \
                      if ([NSParagraphStyle defaultParagraphStyle]. _attr_ == _attr_) return; \
                      style = [NSParagraphStyle defaultParagraphStyle].mutableCopy; \
                  } \
                  style. _attr_ = _attr_; \
                  [self setParagraphStyle:style range:subRange]; \
              }];

- (void)setAlignment:(NSTextAlignment)alignment
{
    [self setAlignment:alignment range:NSMakeRange(0, self.length)];
}

- (void)setAlignment:(NSTextAlignment)alignment range:(NSRange)range
{
    XYParagraphStyleSet(alignment)
}

- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode
{
    [self setLineBreakMode:lineBreakMode range:NSMakeRange(0, self.length)];
}

- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode range:(NSRange)range
{
    XYParagraphStyleSet(lineBreakMode);
}

- (void)setLineSpacing:(CGFloat)lineSpacing
{
    [self setLineSpacing:lineSpacing range:NSMakeRange(0, self.length)];
}

- (void)setLineSpacing:(CGFloat)lineSpacing range:(NSRange)range
{
    XYParagraphStyleSet(lineSpacing);
}

- (void)setParagraphSpacing:(CGFloat)paragraphSpacing
{
    [self setParagraphSpacing:paragraphSpacing range:NSMakeRange(0, self.length)];
}

- (void)setParagraphSpacing:(CGFloat)paragraphSpacing range:(NSRange)range
{
    XYParagraphStyleSet(paragraphSpacing);
}

- (void)setParagraphSpacingBefore:(CGFloat)paragraphSpacingBefore
{
    [self setParagraphSpacingBefore:paragraphSpacingBefore range:NSMakeRange(0, self.length)];
}

- (void)setParagraphSpacingBefore:(CGFloat)paragraphSpacingBefore range:(NSRange)range
{
    XYParagraphStyleSet(paragraphSpacingBefore);
}

- (void)setFirstLineHeadIndent:(CGFloat)firstLineHeadIndent
{
    [self setFirstLineHeadIndent:firstLineHeadIndent range:NSMakeRange(0, self.length)];
}

- (void)setFirstLineHeadIndent:(CGFloat)firstLineHeadIndent range:(NSRange)range
{
    XYParagraphStyleSet(firstLineHeadIndent);
}

- (void)setHeadIndent:(CGFloat)headIndent
{
    [self setHeadIndent:headIndent range:NSMakeRange(0, self.length)];
}

- (void)setHeadIndent:(CGFloat)headIndent range:(NSRange)range
{
    XYParagraphStyleSet(headIndent);
}

- (void)setTailIndent:(CGFloat)tailIndent
{
    [self setTailIndent:tailIndent range:NSMakeRange(0, self.length)];
}

- (void)setTailIndent:(CGFloat)tailIndent range:(NSRange)range
{
    XYParagraphStyleSet(tailIndent);
}

- (void)setMinimumLineHeight:(CGFloat)minimumLineHeight
{
    [self setMinimumLineHeight:minimumLineHeight range:NSMakeRange(0, self.length)];
}

- (void)setMinimumLineHeight:(CGFloat)minimumLineHeight range:(NSRange)range
{
    XYParagraphStyleSet(minimumLineHeight);
}

- (void)setMaximumLineHeight:(CGFloat)maximumLineHeight
{
    [self setMaximumLineHeight:maximumLineHeight range:NSMakeRange(0, self.length)];
}

- (void)setMaximumLineHeight:(CGFloat)maximumLineHeight range:(NSRange)range
{
    XYParagraphStyleSet(maximumLineHeight);
}

- (void)setBaseWritingDirection:(NSWritingDirection)baseWritingDirection
{
    [self setBaseWritingDirection:baseWritingDirection range:NSMakeRange(0, self.length)];
}

- (void)setBaseWritingDirection:(NSWritingDirection)baseWritingDirection range:(NSRange)range
{
    XYParagraphStyleSet(baseWritingDirection);
}

- (void)setHyphenationFactor:(float)hyphenationFactor
{
    [self setHyphenationFactor:hyphenationFactor range:NSMakeRange(0, self.length)];
}

- (void)setHyphenationFactor:(float)hyphenationFactor range:(NSRange)range
{
    XYParagraphStyleSet(hyphenationFactor);
}

- (void)setDefaultTabInterval:(CGFloat)defaultTabInterval
{
    [self setDefaultTabInterval:defaultTabInterval range:NSMakeRange(0, self.length)];
}

- (void)setDefaultTabInterval:(CGFloat)defaultTabInterval range:(NSRange)range
{
    XYParagraphStyleSet(defaultTabInterval);
}

- (void)setTabStops:(NSArray<NSTextTab *> *)tabStops
{
    [self setTabStops:tabStops range:NSMakeRange(0, self.length)];
}

- (void)setTabStops:(NSArray<NSTextTab *> *)tabStops range:(NSRange)range
{
    XYParagraphStyleSet(tabStops);
}


- (void)setRunDelegate:(CTRunDelegateRef)runDelegate range:(NSRange)range
{
    [self setAttribute:(__bridge id)kCTRunDelegateAttributeName value:(__bridge id)runDelegate range:range];
}
@end
